package offer;

public class offerII_0073 {
    public int minEatingSpeed(int[] piles, int h) {
        int len= piles.length;
        int max=piles[0];
        for(int i=0;i<len;++i){
            max=Math.max(max,piles[i]);
        }
        return speed(1,max,piles,h);
    }
    public int speed(int min,int max,int[] piles,int h){
        if(max==min) return max;
        int mid=min+(max-min)/2;
        int time=0;
        for(int i=0;i< piles.length;++i){
            time+=(mid+piles[i]-1)/mid;
        }
        if(time>h){
            return speed(mid+1,max,piles,h);
        }
        return speed(min,mid,piles,h);
    }
}
